package aiaudio.collaborative;

import aiaudio.storage.api.IArtist;
import aiaudio.storage.api.IUser;
import aiaudio.storage.api.RevereUserArtistTuple;
import aiaudio.storage.simple.Artist;
import aiaudio.storage.simple.SimpleIncludeAudioTrainingStorage;
import aiaudio.storage.simple.TooManyItemsException;
import aiaudio.storage.simple.User;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

/**
 *
 * @author Nastya
 */
public class RandomGenerator {

    public static SimpleIncludeAudioTrainingStorage generateRandomStorage(int userCount,
            int artistCount, int userGroupCount) throws TooManyItemsException {
        ArrayList<IUser> users = new ArrayList<IUser>();
        for (int i = 0; i < userCount; i++) {
            users.add(new User(i + ""));
        }

        ArrayList<IArtist> artists = new ArrayList<IArtist>();
        for (int i = 0; i < artistCount; i++) {
            artists.add(new Artist(i + "", "Name" + i));
        }

        Random randomizer = new Random();
        HashMap<RevereUserArtistTuple, Double> ratings =
                new HashMap<RevereUserArtistTuple, Double>();
        for (int i = 0; i < userCount; i++) {
            for (int j = 0; j < artistCount; j++) {
                double rating;
                if (i % userGroupCount == j % userGroupCount) {
                    rating = (double) (randomizer.nextInt(2) + 3) / (double) 5;
                } else {
                    rating = (double) (randomizer.nextInt(1) + 0.1) / (double) 5;
                }
                ratings.put(new RevereUserArtistTuple(artists.get(j),
                        users.get(i)), rating);
            }
        }

        String storageName = String.format(
                "Storage: users = %d, artists = %d, groups = %d",
                userCount, artistCount, userGroupCount);

        SimpleIncludeAudioTrainingStorage storage =
                new SimpleIncludeAudioTrainingStorage(storageName, users,
                artists, ratings);
        return storage;
    }
}
